package com.cn.springcloudvaccine.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cn.springcloudvaccine.mapper.vaccinestation.YmStationMapper;
import com.cn.springcloudvaccine.mapper.vaccinestation.YmStationWorkMapper;
import com.cn.springcloudvaccine.mapper.vaccinestation.YmStationWorkOrderMapper;
import com.cn.springcloudvaccine.mapper.vaccinestation.YmStationWorkTimeMapper;
import com.cn.springcloudvaccine.model.vaccinestion.YmStation;
import com.cn.springcloudvaccine.model.vaccinestion.YmStationWork;
import com.cn.springcloudvaccine.model.vaccinestion.YmStationWorkOrder;
import com.cn.springcloudvaccine.model.vaccinestion.YmStationWorkTime;
import com.cn.springcloudvaccine.service.inter.VaccineStationService;
import com.cn.springcloudvaccine.utils.mybatis.Page;
import com.github.pagehelper.PageHelper;

@Service("VaccineStationService")
public class VaccineStationServiceImpl implements VaccineStationService {

	@Autowired
	YmStationMapper ymStationMapper;
	@Autowired
	YmStationWorkMapper ymStationWorkMapper;
	@Autowired
	YmStationWorkTimeMapper ymStationWorkTimeMapper;
	@Autowired
	YmStationWorkOrderMapper ymStationWorkOrderMapper;
	
	/**
	 * 疫苗站新增
	 * 
	 * @param YmStation ymStation
	 *           
	 * @return SUCC
	 */
	@Override
	public void insertVaccineStationSer(YmStation ymStation,YmStationWorkTime YmStationWorkTime) {
		//新增疫苗站主信息(ym_station)
		ymStationMapper.insertSelective(ymStation);
		//新增疫苗站工作时间站主信息(ym_station_work)
		String[] workDates = ymStation.getWorkTime().split("/");
		YmStationWork YmStationWork = new YmStationWork();
		for(String workDate : workDates){
		YmStationWork.setStationId(ymStation.getStationId());
		YmStationWork.setWorkDate(Integer.parseInt(workDate));
		ymStationWorkMapper.insertSelective(YmStationWork);	
	    }
		String[] times = YmStationWorkTime.getTime().split(",");
		//上班时间段(ym_station_work_time)
		for(String time : times){
			String[] tm = time.split("/");
			YmStationWorkTime.setAmpm(tm[0]);
			YmStationWorkTime.setTime(tm[1]);
			ymStationWorkTimeMapper.insertSelective(YmStationWorkTime);
		}
	}
	
	/**
	 * 疫苗站读取
	 * 
	 * @param YmStation ymStation
	 *           
	 * @return List<YmStation>
	 */
	@Override
	public List<YmStation> queryVaccineStationSer(YmStation ymStation,Page<Object> page) {
		PageHelper.startPage(page.getPageNum(),page.getPageSize());
		List<YmStation> YmStations = ymStationMapper.selectByPrimaryKey(ymStation);
		return YmStations;
	}

	/**
	 * 疫苗站疫苗详情的新增(包括时间段和对应的疫苗)
	 * 
	 * @param YmStationWorkOrder ymStationWorkOrder,String[] parameter(时间段Id)
	 *           
	 * @return SUCC
	 */
	@Override
	public void insertVaccineStationDetailSer(YmStationWorkOrder ymStationWorkOrder,String[] parameter) {
		ymStationWorkOrder.getStationId();
		ymStationWorkOrder.getVaccineId();
		for(String pt : parameter){
		ymStationWorkOrder.setWorkTimeDescId(Long.parseLong(pt));
		ymStationWorkOrderMapper.insertSelective(ymStationWorkOrder);
		}
	}

	/**
	 * 查询某一个疫苗站疫苗(包括时间段和对应的疫苗)
	 * 
	 * @param YmStation ymStation
	 *           
	 * @return List<YmStation>
	 */
	@Override
	public List<YmStation> queryVaccineStationDetailSer(YmStation ymStation) {
		return ymStationMapper.queryVaccineStationDetailMapper(ymStation);
	}

}
